package cn.itcast.mq.listener;

import org.mockito.internal.matchers.Null;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import sun.awt.SunHints;

import javax.xml.ws.BindingType;
import java.time.LocalDateTime;

@Component
public class SpringAmqpListener {
    //    @RabbitListener(queues = "simple.queue")
//    public void  listenSimpleQueueMessage1(String message1) throws InterruptedException {
//
//        System.out.println("消费者1正在消费消息"+message1+"," +LocalDateTime.now());
//        Thread.sleep(20);
//    }
//    @RabbitListener(queues = "simple.queue")
//    public void  listenSimpleQueueMessage2(String message2) throws InterruptedException {
//
//        System.err.println("消费者2正在消费消息"+ message2+"," +LocalDateTime.now());
//        Thread.sleep(80);
//    }
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "fanout.queue1"),
            exchange = @Exchange(name = "itcast.fanout", type = ExchangeTypes.FANOUT),
            key = "#.#"
    ))
    public void listenSimpleQueueMessage1(String message)  {
        System.out.println("消费者接收到fonout.queue1消费消息" + message);
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "fanout.queue2"),
            exchange = @Exchange(name = "itcast.fanout", type = ExchangeTypes.FANOUT)
    ))

    public void listenSimpleQueueMessage2(String message)  {
        System.out.println("消费者接收到fonout.queue2消费消息" + message);
    }
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue1"),
            exchange = @Exchange(name = "itcast.direct", type = ExchangeTypes.DIRECT),
            key = {"red", "blue"}

    ))
    public void listenSimpleQueueMessage3(String message)  {
        System.out.println("消费者接收到direct.queue1消费消息" + message);
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue2"),
            exchange = @Exchange(name = "itcast.direct", type = ExchangeTypes.DIRECT),
            key = {"red", "yellow"}
    ))

    public void listenSimpleQueueMessage4(String message)  {
        System.out.println("消费者接收到direct.queue2消费消息" + message);
    }
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "topic.queue1"),
            exchange = @Exchange(name = "itcast.topic", type = ExchangeTypes.TOPIC),
            key = "china.#"

    ))
    public void listenSimpleQueueMessage5(String message) {
        System.out.println("消费者接收到topic.queue1消费消息" + message);
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "topic.queue2"),
            exchange = @Exchange(name = "itcast.topic", type = ExchangeTypes.TOPIC),
            key ="#.new"
    ))

    public void listenSimpleQueueMessage6(String message)  {
        System.out.println("消费者接收到topic.queue2消费消息" + message);
    }
}
